package com.lex.cheeseStrip.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lex.cheeseStrip.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Mc on 2016/11/28.
 */

public class AdapterDemo extends BaseAdapter {

    private Context context;
    private ViewHolder mHolder;
    private String[] string;

    public AdapterDemo(Context context, String[] string) {
        this.context = context;
        this.string = string;
    }

    @Override
    public int getCount() {
        return string.length;
    }

    @Override
    public Object getItem(int i) {
        return string[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        mHolder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_demo, parent, false);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        mHolder.tv_demo.setText(string[position]);


        return convertView;


    }


    class ViewHolder {

        @BindView(R.id.tv_demo)
        TextView tv_demo;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
